import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution2013 {

    Map<List<Integer>,Integer> map1=new HashMap<>();
    Map<Integer,List<Integer>> map2=new HashMap<>();

    public Solution2013() {

    }

    public void add(int[] point) {
        List<Integer> list=new ArrayList<>();
        list.add(point[0]);
        list.add(point[1]);
        map1.put(list, map1.getOrDefault(list,0)+1);
        List<Integer> list1=map2.getOrDefault(point[0],new ArrayList<>());
        list1.add(point[1]);
        map2.put(point[0],list1);
    }

    public int count(int[] point) {
        List<Integer> list=map2.getOrDefault(point[0],new ArrayList<>());
        int ans=0;
        for (Integer integer : list) {
            if (integer!=point[1]){
                List<Integer> l1=new ArrayList<>();
                l1.add(point[0]+Math.abs(integer-point[1]));
                l1.add(integer);
                int p=map1.getOrDefault(l1,0);
                List<Integer> l2=new ArrayList<>();
                l2.add(point[0]+Math.abs(integer-point[1]));
                l2.add(point[1]);
                int q=map1.getOrDefault(l2,0);
                ans=ans+p*q;
                l1=new ArrayList<>();
                l1.add(point[0]-Math.abs(integer-point[1]));
                l1.add(integer);
                p=map1.getOrDefault(l1,0);
                l2=new ArrayList<>();
                l2.add(point[0]-Math.abs(integer-point[1]));
                l2.add(point[1]);
                q=map1.getOrDefault(l2,0);
                ans=ans+p*q;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution2013 detectSquares = new Solution2013();
        detectSquares.add(new int[]{3, 10});
        detectSquares.add(new int[]{11, 2});
        detectSquares.add(new int[]{3, 2});
        System.out.println(detectSquares.count(new int[]{11, 10}));
        System.out.println(detectSquares.count(new int[]{14, 8}));
        detectSquares.add(new int[]{11, 2});
        System.out.println(detectSquares.count(new int[]{11, 10}));
    }
}
